package com.zuoye.day11;

public class ListNode {

    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

class Solution {
    int val = 0;
    public  ListNode removeNthFromEnd(ListNode head, int n) {
        if (head == null || n < 0) {
            return head;
        }
        ListNode n1 = head;
        ListNode n2 = head;
        for (int i = 0;i < n;i++){
            n1 = n1.next;
        }
        while (n1.next != null){
            n1 = n1.next;
            n2 = n2.next;
        }
        n2.next = n2.next.next;
        return head;


        }

    }






